import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/viewmodel/event_manage/add_event_follow_view_model.dart';

import '../../res/colors.dart';
import '../../util/utils.dart';
import '../../viewmodel/event_manage/event_manage_list_viewmodel.dart';
import '../../widgets/add_image_widget.dart';

class AddEventFollowPage extends BaseStatefulMvvmWidget {
  final dynamic eventId;

  AddEventFollowPage({@required this.eventId});

  @override
  State<StatefulWidget> createState() => _AddEventFollowState();
}

class _AddEventFollowState
    extends BaseMvvmState<AddEventFollowViewModel, AddEventFollowPage> {
  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        SizedBox(
          height: 20,
        ),
        CommonInput(
          isDense: true,
          padding: EdgeInsets.zero,
          border: InputBorder.none,
          hintText: '请输入事件跟踪记录',
          minLines: 7,
          maxLines: 7,
          onChanged: (str) {
            viewModel.detail = str;
          },
          keyboardType: CommonInputType.multiline,
        ).addToContainer(
            decoration: BoxDecoration(
                color: Colours.bg_color, borderRadius: 10.borderRadius),
            margin: EdgeInsets.symmetric(horizontal: 16),
            padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10)),
        SizedBox(
          height: 16,
        ),
        AddAndUploadImageWidget(
          (files, modelList) {
           setState(() {
             viewModel.files = files;
           });
          },
          files: viewModel.files,
          cameramsg: "拍摄事件跟进照片，需要申请您的相机权限",
          photomsg: "从相册选取事件跟进照片，需要申请您的相册权限",
        ),
        SizedBox(
          height: 16,
        ),
        Row(
          children: [
            SizedBox(width: 16,),
            TextButton(
              onPressed: () {
                viewModel.createFollow(false);
              },
              child: CommonText('继续跟踪', textColor: Colors.white),
              style: ButtonStyle(
                  backgroundColor: WidgetStateProperty.all(Colors.blue),
                  shape: WidgetStateProperty.all(StadiumBorder()),
                  minimumSize: WidgetStateProperty.all(
                      Size(MediaQuery.of(context).size.width - 32, 49))),
            ).setWeight(1),
            SizedBox(
              width: 20,
            ),
            TextButton(
              onPressed: () {
                viewModel.createFollow(true);
              },
              child: CommonText('结束跟踪', textColor: Colors.white),
              style: ButtonStyle(
                  backgroundColor: WidgetStateProperty.all(Colors.blue),
                  shape: WidgetStateProperty.all(StadiumBorder()),
                  minimumSize: WidgetStateProperty.all(
                      Size(MediaQuery.of(context).size.width - 32, 49))),
            ).setWeight(1),
            SizedBox(width: 16,),
          ],
        )
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        title: Text('事件跟踪'),
        actions: [
          IconButton(onPressed: (){
            Utils.launchTelURL(sosPhone);
          }, icon: Icon(Icons.call))
        ],
      ),
      body: loadingContentWidget,
    );
  }

  @override
  AddEventFollowViewModel createViewModel() {
    return AddEventFollowViewModel(context, eventId: widget.eventId);
  }

  @override
  void onRetryClick() {}
}
